package com.homework.news

import android.os.Build
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.StrictMode
import android.webkit.WebChromeClient
import android.webkit.WebView

class VideoDetailActivity : AppCompatActivity() {

    var webView: WebView? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_video_detail)
        //允许在主线程请求网络
        if (Build.VERSION.SDK_INT > 9) {
            val policy = StrictMode.ThreadPolicy.Builder().permitAll().build()
            StrictMode.setThreadPolicy(policy)
        }
        webView = findViewById(R.id.webView)
        val video: Video = intent.getSerializableExtra("video") as Video
        val videoUrl = video.share_url.replace("\\", "").substring(0, video.share_url.indexOf("?"))
        println(videoUrl)
        webView?.settings?.javaScriptEnabled = true
        webView?.settings?.domStorageEnabled = true;
        webView?.webChromeClient = WebChromeClient()
        webView?.loadUrl(videoUrl)
    }
}